<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
    <link rel="stylesheet" href="${basePath}/assets/css/foundation-datepicker.css"/>
	<script type="text/javascript" src="${basePath}/assets/js/foundation-datepicker.js"></script>
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/userTask/updateUserTask">
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-3 control-label">任务名称：</label>
            <div class="col-sm-9">
                <input class="col-sm-5" type="text" name="userName" id="userName" value = "${userTaskVo.title}" readonly="true"/>
                <input type="hidden" name="taskId" id="taskId" value = "${userTaskVo.taskId}" />
                <input type="hidden" name="plDays" id="plDays" value = "${userTaskVo.plDays}" />
                <input type="hidden" name="userId" id="userId" value = "${userTaskVo.userId}" />
                <input type="hidden" name="userTaskId" id="userTaskId" value = "${userTaskVo.userTaskId}" />
                <input type="hidden" name="alloterId" id="alloterId" value = "${userTaskVo.alloterId}" />
                <input type="hidden" class="col-sm-5" id="createTime" name="createTime" value="<fmt:formatDate value='${userTaskVo.createTime}' type='both'/>"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分配人员：</label>
            <div class="col-sm-9">
                <input class="col-sm-5" type="text" name="userName" id="userName" value = "${userTaskVo.userName}" readonly="true"/>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label">计划开始时间：</label>
            <div class="col-sm-9">
                <input type="text"  id="startTimePl" name="startTimePl" value="<fmt:formatDate value="${userTaskVo.startTimePl}" type="date"/>" readonly/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">计划结束时间：</label>
            <div class="col-sm-9">
                <input type="text"  id="endTimePl" name="endTimePl" value = "<fmt:formatDate value="${userTaskVo.endTimePl}" type="date"/>"  readonly/>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label">实际开始时间：</label>
            <div class="col-sm-9">
                <input type="text" class="date-icon" id="startTimeReal" name="startTimeReal" value="<fmt:formatDate value="${userTaskVo.startTimeReal}" type="date"/>" readonly/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">实际结束时间：</label>
            <div class="col-sm-9">
                <input type="text" class="date-icon" id="endTimeReal" name="endTimeReal" value="<fmt:formatDate value="${userTaskVo.endTimeReal}" type="date"/>"  readonly/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">任务完成说明：</label>
            <div class="col-sm-9">
                <textarea id="completeDes" name="completeDes" rows="5" cols="30">${userTaskVo.completeDes}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-9">
                <textarea id="userTaskDes" name="userTaskDes" rows="5" cols="30" readonly>${userTaskVo.userTaskDes}</textarea>
            </div>
        </div>
        <button id="submit" type="submit" class="btn btn-primary btn-submit">提交</button>
    </div>
</form>
<script type="text/javascript">


	//alert(parent.taskTitle+"--------");
	
	$("#title").val(parent.taskTitle);
	$("#taskId").val(parent.taskId);
	//alert($("#taskId").val());
    jQuery(function ($) {
    	
    	$('.date-icon').fdatepicker({
            format: 'yyyy-mm-dd'
        });
    	jQuery.validator.methods.compareDate = function(value, element, param) {
            var startDate = jQuery(param).val();
            //alert(param+"--"+value);
            var date1 = new Date(Date.parse(startDate.replace("-", "/")));
            var date2 = new Date(Date.parse(value.replace("-", "/")));
            return date1 < date2;
        };
        var $form = $("#form");
        var $startTimeReal = $("#startTimeReal");
        var $endTimeReal = $("#endTimeReal");
        var $completeDes = $("#completeDes");
        var $submit = $("#submit");

        $form.validate({
            errorClass: 'error-msg',
            
            rules: {
            	startTimeReal: {
                    required: true
                },
                endTimeReal: {
                    required: true,
                    compareDate: "#startTimePl"
                },
                completeDes:{
                	rangelength:[0,100]
                } 

            },
            messages: {
            	startTimeReal: "实际开始时间必填*",
            	endTimeReal:{
                	required:"实际结束时间必填*",
                	compareDate:"实际结束日期必须大于实际开始日期!"
                },
                completeDes:"任务完成说明长度不能超过100！*"
            },
            submitHandler: function (form) {
                $.ajax({
                    url: $form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $submit.prop("disabled", true);
                    },
                    success: function (data) {
                    	//alert(data);
                        if (data.status == '0') {
                            $submit.prop("disabled", false);
                            layer.confirm('任务修改成功！是否关闭窗口？', {icon: 1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageii);
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });


    });
</script>
</body>
</html>
